'use strict';
exports.main = async (event, context) => {
  const { page = 1, pageSize = 10 } = event;
  const db = uniCloud.database();
  
  try {
    const res = await db.collection('items')
      .orderBy('created_at', 'desc')
      .skip((page - 1) * pageSize)
      .limit(pageSize)
      .get();
    
    return {
      code: 0,
      data: res.data
    };
  } catch (e) {
    return {
      code: 500,
      msg: '获取商品失败'
    };
  }
};